home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / os2 / sysb091a.zip / sysbench / src / pmb_flops.c < prev    next >
C/C++ Source or Header  |  1996-05-18  |  32KB  |  1,011 lines

  1. /*--------------------- Start flops.c source code ----------------------*/
  2.  
  3. /*****************************/
  4. /*          FLOPS.c          */
  5. /* Version 2.0,  18 Dec 1992 */
  6. /*         Al Aburto         */
  7. /*  aburto@marlin.nosc.mil   */
  8. /*       'ala' on BIX        */
  9. /*****************************/
  10.  
  11. /*
  12.    Flops.c is a 'c' program which attempts to estimate your systems
  13.    floating-point 'MFLOPS' rating for the FADD, FSUB, FMUL, and FDIV
  14.    operations based on specific 'instruction mixes' (discussed below).
  15.    The program provides an estimate of PEAK MFLOPS performance by making
  16.    maximal use of register variables with minimal interaction with main
  17.    memory. The execution loops are all small so that they will fit in
  18.    any cache. Flops.c can be used along with Linpack and the Livermore
  19.    kernels (which exersize memory much more extensively) to gain further
  20.    insight into the limits of system performance. The flops.c execution
  21.    modules also include various percent weightings of FDIV's (from 0% to
  22.    25% FDIV's) so that the range of performance can be obtained when
  23.    using FDIV's. FDIV's, being computationally more intensive than
  24.    FADD's or FMUL's, can impact performance considerably on some systems.
  25.  
  26.    Flops.c consists of 8 independent modules (routines) which, except for
  27.    module 2, conduct numerical integration of various functions. Module
  28.    2, estimates the value of pi based upon the Maclaurin series expansion
  29.    of atan(1). MFLOPS ratings are provided for each module, but the
  30.    programs overall results are summerized by the MFLOPS(1), MFLOPS(2),
  31.    MFLOPS(3), and MFLOPS(4) outputs.
  32.  
  33.    The MFLOPS(1) result is identical to the result provided by all
  34.    previous versions of flops.c. It is based only upon the results from
  35.    modules 2 and 3. Two problems surfaced in using MFLOPS(1). First, it
  36.    was difficult to completely 'vectorize' the result due to the
  37.    recurrence of the 's' variable in module 2. This problem is addressed
  38.    in the MFLOPS(2) result which does not use module 2, but maintains
  39.    nearly the same weighting of FDIV's (9.2%) as in MFLOPS(1) (9.6%).
  40.    The second problem with MFLOPS(1) centers around the percentage of
  41.    FDIV's (9.6%) which was viewed as too high for an important class of
  42.    problems. This concern is addressed in the MFLOPS(3) result where NO
  43.    FDIV's are conducted at all.
  44.  
  45.    The number of floating-point instructions per iteration (loop) is
  46.    given below for each module executed:
  47.  
  48.    MODULE   FADD   FSUB   FMUL   FDIV   TOTAL  Comment
  49.      1        7      0      6      1      14   7.1%  FDIV's
  50.      2        3      2      1      1       7   difficult to vectorize.
  51.      3        6      2      9      0      17   0.0%  FDIV's
  52.      4        7      0      8      0      15   0.0%  FDIV's
  53.      5       13      0     15      1      29   3.4%  FDIV's
  54.      6       13      0     16      0      29   0.0%  FDIV's
  55.      7        3      3      3      3      12   25.0% FDIV's
  56.      8       13      0     17      0      30   0.0%  FDIV's
  57.  
  58.    A*2+3     21     12     14      5      52   A=5, MFLOPS(1), Same as
  59.         40.4%  23.1%  26.9%  9.6%          previous versions of the
  60.                            flops.c program. Includes
  61.                            only Modules 2 and 3, does
  62.                            9.6% FDIV's, and is not
  63.                            easily vectorizable.
  64.  
  65.    1+3+4     58     14     66     14     152   A=4, MFLOPS(2), New output
  66.    +5+6+    38.2%  9.2%   43.4%  9.2%          does not include Module 2,
  67.    A*7                                         but does 9.2% FDIV's.
  68.  
  69.    1+3+4     62      5     74      5     146   A=0, MFLOPS(3), New output
  70.    +5+6+    42.9%  3.4%   50.7%  3.4%          does not include Module 2,
  71.    7+8                                         but does 3.4% FDIV's.
  72.  
  73.    3+4+6     39      2     50      0      91   A=0, MFLOPS(4), New output
  74.    +8       42.9%  2.2%   54.9%  0.0%          does not include Module 2,
  75.                            and does NO FDIV's.
  76.  
  77.    NOTE: Various timer routines are included as indicated below. The
  78.      timer routines, with some comments, are attached at the end
  79.      of the main program.
  80.  
  81.    NOTE: Please do not remove any of the printouts.
  82.  
  83.    EXAMPLE COMPILATION:
  84.    UNIX based systems
  85.       cc -DUNIX -O flops20.c -o flops
  86.       cc -DUNIX -DROPT flops20.c -o flops
  87.       cc -DUNIX -fast -O4 flops20.c -o flops
  88.       .
  89.       .
  90.       .
  91.      etc.
  92.  
  93.    Al Aburto
  94.    aburto@marlin.nosc.mil
  95. */
  96.  
  97. //#include <stdio.h>
  98. #define INCL_DOSMISC
  99. #include <math.h>
  100. #include <os2.h>
  101.                  /* 'Uncomment' the line below to run   */
  102.                  /* with 'register double' variables    */
  103.                  /* defined, or compile with the        */
  104.                  /* '-DROPT' option. Don't need this if */
  105.                  /* registers used automatically, but   */
  106.                  /* you might want to try it anyway.    */
  107. /* #define ROPT */
  108.  
  109. /***************************************************************/
  110. /* Timer options. You MUST uncomment one of the options below  */
  111. /* or compile, for example, with the '-DUNIX' option.          */
  112. /***************************************************************/
  113. /* #define Amiga       */
  114. /* #define UNIX        */
  115. /* #define UNIX_Old    */
  116. /* #define VMS         */
  117. /* #define BORLAND_C   */
  118. /* #define MSC         */
  119. /* #define MAC         */
  120. /* #define IPSC        */
  121. /* #define FORTRAN_SEC */
  122. /* #define GTODay      */
  123. /* #define CTimer      */
  124. /* #define UXPM        */
  125.  
  126. static double nulltime, TimeArray[3];   /* Variables needed for 'flops_time()'.     */
  127. static double TLimit;                   /* Threshold to determine Number of    */
  128.                  /* Loops to run. Fixed at 15.0 seconds.*/
  129.  
  130. static double T[36];                    /* Global Array used to hold timing    */
  131.                  /* results and other information.      */
  132.  
  133. static double sa,sb,sc,sd,one,two,three;
  134. static double four,five,piref,piprg;
  135. static double scale,pierr;
  136.  
  137. static double A0 = 1.0;
  138. static double A1 = -0.1666666666671334;
  139. static double A2 = 0.833333333809067E-2;
  140. static double A3 = 0.198412715551283E-3;
  141. static double A4 = 0.27557589750762E-5;
  142. static double A5 = 0.2507059876207E-7;
  143. static double A6 = 0.164105986683E-9;
  144.  
  145. static double B0 = 1.0;
  146. static double B1 = -0.4999999999982;
  147. static double B2 = 0.4166666664651E-1;
  148. static double B3 = -0.1388888805755E-2;
  149. static double B4 = 0.24801428034E-4;
  150. static double B5 = -0.2754213324E-6;
  151. static double B6 = 0.20189405E-8;
  152.  
  153. static double C0 = 1.0;
  154. static double C1 = 0.99999999668;
  155. static double C2 = 0.49999995173;
  156. static double C3 = 0.16666704243;
  157. static double C4 = 0.4166685027E-1;
  158. static double C5 = 0.832672635E-2;
  159. static double C6 = 0.140836136E-2;
  160. static double C7 = 0.17358267E-3;
  161. static double C8 = 0.3931683E-4;
  162.  
  163. static double D1 = 0.3999999946405E-1;
  164. static double D2 = 0.96E-3;
  165. static double D3 = 0.1233153E-5;
  166.  
  167. static double E2 = 0.48E-3;
  168. static double E3 = 0.411051E-6;
  169.  
  170. int flops_time(double *p);
  171.  
  172. double pmb_flops()
  173. {
  174.  
  175. #ifdef ROPT
  176.    register double s,u,v,w,x;
  177. #else
  178.    double s,u,v,w,x;
  179. #endif
  180.  
  181.    long loops, NLimit;
  182.    register long i, m, n;
  183.  
  184. //   printf("\n");
  185. //   printf("   FLOPS C Program (Double Precision), V2.0 18 Dec 1992\n\n");
  186.  
  187.                /****************************/
  188.    loops = 15625;      /* Initial number of loops. */
  189.                /*     DO NOT CHANGE!       */
  190.                /****************************/
  191.  
  192. /****************************************************/
  193. /* Set Variable Values.                             */
  194. /* T[1] references all timing results relative to   */
  195. /* one million loops.                               */
  196. /*                                                  */
  197. /* The program will execute from 31250 to 512000000 */
  198. /* loops based on a runtime of Module 1 of at least */
  199. /* TLimit = 15.0 seconds. That is, a runtime of 15  */
  200. /* seconds for Module 1 is used to determine the    */
  201. /* number of loops to execute.                      */
  202. /*                                                  */
  203. /* No more than NLimit = 512000000 loops are allowed*/
  204. /****************************************************/
  205.  
  206.    T[1] = 1.0E+06/(double)loops;
  207.  
  208.    TLimit